<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <title>管理员添加公告页面</title>
</head>
<?php 
include_once("inc.php");
include_once("base.php");
$tb_name = "news";
$rs = array();
if ($_REQUEST["id"]) {
	$rs = db_get_row("select * from $tb_name where id=". $_REQUEST["id"]);
}
if ($_POST){
	$data = array();
	if ($_REQUEST["id"]) {
		if($_POST["title"]!=$_POST["title1"]){
			$row1 = db_get_row("select * from $tb_name where title='". $_POST["title"] ."'");
			if ($row1["id"]) {
				goBakMsg("已存在，请重新填写");
				die;
			}
		}
	} else {
		$row1 = db_get_row("select * from $tb_name where title='". $_POST["title"] ."'");
			if ($row1["id"]) {
				goBakMsg("已存在，请重新填写");
				die;
		}
	}
	$data["title"] = "'".$_POST["title"]."'";
	$data["content"] = "'".$_POST["content"]."'";
	if ($_REQUEST["id"]) {
		db_mdf($tb_name,$data,$_REQUEST["id"]);
	} else {
		db_add($tb_name,$data);
	}
	urlMsg("提交成功", $tb_name."_list.php");
	die;
}
?>
<script>
function checkadd()
{
	if (document.form1.title.value=='')
	{
	alert('标题不能为空');
	document.form1.title.focus;
	return false
	}
	if (document.form1.content.value=='')
	{
	alert('公告内容不能为空');
	document.form1.content.focus;
	return false
	}
}
</script>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td width="17" rowspan="2" valign="top" bgcolor="#FFFFFF"></td>
		<td valign="top">
			<table width="100%" height="31" border="0" cellpadding="0" cellspacing="0">
				<tr bgcolor="#FFFFFF">
					<td height="31">
						<div class="title">添加/修改信息</div>
					</td>
				</tr>
			</table>
		</td>
		<td width="16" rowspan="2" bgcolor="#FFFFFF"></td>
	</tr>
	<tr>
		<td valign="top" bgcolor="#F7F8F9">
			<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
				<tr><td colspan="4" height="10"></td></tr>
				<tr>
					<td width="1%">&nbsp;</td>
					<td width="96%">
						<table width="100%">
							<tr>
								<td colspan="2">
									<form name="form1" method="post" action="?" onSubmit="return checkadd()"  enctype="multipart/form-data">
										<input type="hidden" name="id" value="<?php echo $rs["id"];?>" />
										<input type="hidden" name="title1" value="<?php echo $rs["title"];?>" />
										<table width="100%" class="cont">
											<tr>
												<td width="120" align="right"><span class="red">*</span>标题：</td>
												<td><input name="title" type="text" class="text" size="30" value="<?php echo $rs["title"];?>"></td>
											</tr>
											<tr>
												<td align="right">详情：</td>
												<td>
													<script src="./kindeditor/kindeditor-all-min.js"></script>
													<script src="./kindeditor/lang/zh-CN.js"></script>
													<script>
													    //编辑器
													    var KE;
													    KindEditor.ready(function (K) {
													        KE = K.create('#Contents', {
													            allowFileManager: true, //浏览图片空间
													            filterMode: false, //HTML特殊代码过滤
													            afterBlur: function () { this.sync(); }, //编辑器失去焦点(blur)时执行的回调函数（将编辑器的HTML数据同步到textarea）
													            afterUpload: function (url, data, name) { //上传文件后执行的回调函数，必须为3个参数
													                if (name == "image" || name == "multiimage") { //单个和批量上传图片时
													                    var img = new Image(); img.src = url;
													                    img.onload = function () { //图片必须加载完成才能获取尺寸
													                        if (img.width > 100) {
													                            KE.html(KE.html().replace('<img src="' + url + '" width="100" height="100"/>', '<img src="' + url + '" width="100" height="100px"/>'))
													                            //KE.html(KE.html().replace('<img src="' + url + '" width="300"/>', '<img src="' + url + '" width="300"/>'))
													                        }
													 
													                    }
													                }
													            }
													        });
													        KindEditor.create('#Contents', { allowImageUpload: false, resizeType: 1, width: "600px", height: "300px" });
													    });
													</script>
													<textarea name="content" id="Contents" style="width: 600px; height: 450px;">
														<?php echo $rs['content'];?>
													</textarea>
												</td>
											</tr>
											<tr>
												<td align="right"></td>
												<td>
													<input class="btn" type="submit" value="提交" id="submitBtn" />
													<input name="button" type="button" class="btn" onClick="javascript:history.back();" value="返回">
												</td>
											</tr>
										</table>
									</form>
								</td>
							</tr>
						</table>
					</td>
					<td width="1%">&nbsp;</td>
				</tr>
				<tr><td height="20"></td></tr>
			</table>
		</td>
	</tr>
</table>
</body>
</html>